package shujia.day11;

import java.util.TreeSet;

/*
    使用TreeSet存储自定义对象并遍历
    当教师的姓名和年龄一样的时候，认为发生重复

    需求：将教师对象添加到TreeSet集合中，去重的同时，按照年龄从小到大排序

    自然排序要求元素类要实现Comparable接口，并重写compareTo方法
    而compareTo方法中的结果返回值，取决于需求来编写代码逻辑


 */
public class TreeSetDemo2 {
    public static void main(String[] args) {
        TreeSet<Teacher> set1 = new TreeSet<>();

        Teacher t1 = new Teacher("小虎", 18);
        Teacher t2 = new Teacher("杨老板", 16);
        Teacher t3 = new Teacher("笑哥", 19);
        Teacher t4 = new Teacher("旭哥", 15);
        Teacher t5 = new Teacher("小虎", 18);
        Teacher t6 = new Teacher("强哥", 18);

        set1.add(t1);
        set1.add(t2);
        set1.add(t3);
        set1.add(t4);
        set1.add(t5);
        set1.add(t6);

        for (Teacher teacher : set1) {
            System.out.println(teacher);
        }



    }
}
